﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;
using MyGeneration.dOOdads;

namespace POSSystem.BLL
{
    public  class CustomerOrders : _CustomerOrders
    {
        public static int GetStatus(int id)
        {
            try
            {
                CustomerOrders order = new CustomerOrders();
                order.Where.ID.Value = id;
                order.Query.AddResultColumn(CustomerOrders.ColumnNames.StatusID);
                order.Query.Load();

                return order.RowCount > 0 ? order.StatusID : 0;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("CustomerOrders", "GetStatus", ex.StackTrace);
                throw ex;
            }
        }

        public static CustomerOrders GetByVoucherId(Guid id)
        {
            POSSystem.BLL.CustomerOrders order = new CustomerOrders();
            order.Where.VoucherID.Value = id;
            order.Where.Deleted.Value = false;
            order.Query.Load();

            return order;
        }

        public static CustomerOrders GetPendingOrdersByVoucherId(Guid id)
        {
            POSSystem.BLL.CustomerOrders order = new CustomerOrders();
            order.Where.VoucherID.Value = id;
            order.Where.StatusID.Value = (int)OrderStatus.Pending;
            order.Where.Deleted.Value = false;
            order.Query.Load();

            return order;
        }

        public static CustomerOrders GetOrdersByIds(string ids)
        {
            POSSystem.BLL.CustomerOrders order = new POSSystem.BLL.CustomerOrders();
            order.Where.ID.Value = ids;
            order.Where.ID.Operator = WhereParameter.Operand.In;
            order.Query.Load();

            return order;
        }

        public static CustomerOrders GetOrdersById(int id)
        {
            POSSystem.BLL.CustomerOrders order = new POSSystem.BLL.CustomerOrders();
            order.Where.ID.Value = id;
            order.Query.Load();

            return order;
        }
    }
}
